<!--
 Copyright 2025 Google LLC

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<div class="chat-container">
  <div class="chat-body">

    <!-- sugesstion along with a response -->
    <div class="bot-message" *ngIf="showSuggesstion" class="bot-suggestion-container">
      <div class="bot-suggestion-container-child">
        <app-suggestion-card [data]="getSuggestionData(this.suggestedQuestionMessage)"
          (raiseQuery)="getResponseforSuggestionQuery($event)"
          (dismissSuggestionCard)="removeSuggestionElement()"></app-suggestion-card>
      </div>
    </div>

    <!-- Loader -->
    <div *ngIf="showLoader">
      <div class="loader">
        <div class="{{leftContainerClass}}"></div>
        <div class="loader-child-container {{rightContainerClass}}">
          <div [ngClass]="showLoaderLikeDislikeButtons? 'loader-text-container':''">
            <markdown class="variable-binding" [data]="loaderText"></markdown>
          </div>
          <div *ngIf="showLoaderLikeDislikeButtons" class="like-dislike-button">
          </div>
        </div>
      </div>
    </div>

    <!-- Chat section for the messages -->
    <ng-container *ngFor="let message of conversation;index as i">

      <div class="user-message" *ngIf="message.type == 'user'">
        <div class="user-message-wrapping-container">
          <div class="messageContent">
            {{message.body}}
          </div>
          <div class="user-circle" *ngIf="requiredLogin === 'True' && userService.getUserDetails().photoURL">
            <img [src]="userService.getUserDetails().photoURL" class="logo-icon" />
          </div>
          <div *ngIf="requiredLogin === 'False'" class="user-icon">
            <mat-icon class="bypassMenuLogo">person</mat-icon>
          </div>
        </div>
      </div>


      <div class="bot-message"
        *ngIf="message.type == 'bot' && (!message.suggestedQuestion?.length || 0 > 0)"
        id="{{message.botStartTime}}">
        <div class="bot-message-wrapping-container">
          <div class="bot-message-action">
            <div></div>
            <!-- <img src="../../../../../assets/images/user-logo.svg" /> -->
          </div>

          <div class="bot-message-content">
            <markdown clipboard class="variable-binding" [data]="message.body"></markdown>
            <markdown *ngIf="message.botAnswer" clipboard class="variable-binding"
              [data]="getStringData(message.botAnswer)">
            </markdown>
            <div class="action-content" *ngIf="message.shareable">
              <div class="action-message"></div>
              <div class="action-butons" *ngIf="message.chat_id">
              </div>
            </div>
          </div>

        </div>
        <span class="generating-text" *ngIf="message.responseTime">Generated in {{message.responseTime}}s</span>
      </div>

    </ng-container>

  </div>
  <div class="chat-footer-outer">
    <div [ngStyle]="{'opacity':this.isChatDisabled ? '30%' : '100%' }" class="chat-footer">
      <div class="chat-textarea">
        <textarea [disabled]="this.isChatDisabled"
          [placeholder]="!this.isChatDisabled ?  'Type your question here, make sure to add context' : ''"
          [(ngModel)]="chatQuery" (keydown.enter)="submitMessage($event)"
          (paste)="removeSuggestionElement();"
          (keypress)="removeSuggestionElement();">
        </textarea>
      </div>
      <div class="micIcon">
        <button mat-icon-button (click)="startRecording()" matTooltip="Record"
          *ngIf="!isRecording"><mat-icon>mic_none</mat-icon>
        </button>
        <span (click)="stopRecording()" class="recording-container" *ngIf="isRecording">
          <span class="blue-dot">&nbsp;</span>
          <span class="green-dot">&nbsp;</span>
          <span class="yellow-dot">&nbsp;</span>
          <button (click)="stopRecording()" style="color: red;" class="reset-button initial" mat-icon-button
            matTooltip="Stop Recording" aria-label="record button">
            <mat-icon class="material-icons-outlined">stop_circle</mat-icon> </button>
        </span>
        <button (click)="resetBrowser()" class="reset-button initial" mat-icon-button aria-label="Share icon button">
          <span class="material-symbols-rounded send-icon">refresh</span>
        </button>

        <button mat-icon-button (click)="submitMessage($event)">
          <mat-icon class="send-icon">send</mat-icon>
        </button>
      </div>
    </div>
  </div>
</div>
